package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.LabelInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.admin.service.LabelInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.io.ResolverUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: LabelController
 * Package: com.atguigu.lease.web.admin.controller.apartment
 * Description:
 *
 * @Author ygf
 * @Create 2024/9/6 15:43
 * @Version 1.0
 */
@Tag(name = "标签管理接口")
@RestController
@RequestMapping("/admin/label")
public class LabelInfoController {


    @Autowired
    private LabelInfoService labelInfoService;


    @Operation(summary = "新增或修改标签信息")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody LabelInfo labelInfo){
        //调用service层
        labelInfoService.saveOrUpdate(labelInfo);
        return Result.ok();
    }

    @Operation(summary = "根据id删除标签信息")
    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam Long id){
        labelInfoService.removeById(id);
        return Result.ok();
    }

    @Operation(summary = "根据类型查询标签列表")
    @GetMapping("/list")
    public Result list(@RequestParam(required = false) ItemType type){
        //调用service层
        LambdaQueryWrapper<LabelInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(type != null,LabelInfo::getType,type);//这个条件及根据前端传递的参数和数据库的字段作比较
        List<LabelInfo> labelInfoList = labelInfoService.list(queryWrapper);
        return Result.ok(labelInfoList);
    }


}
